//
//  HMEmoticonSectionModel.swift
//  表情键盘
//
//  Created by WGP on 16/4/20.
//  Copyright © 2016年 WGP. All rights reserved.
//

import UIKit

class HMEmoticonSectionModel: NSObject {
    
    var id: String
    
    var group_name_cn: String
    
    var emoticons:[HMEmoticonModel]
    
    var pageEmoticons: [[HMEmoticonModel]] = [[HMEmoticonModel]]()
    
    init(id: String, group_name_cn: String, emoticons:[HMEmoticonModel]) {
        
        self.id = id
        self.group_name_cn = group_name_cn
        self.emoticons = emoticons
//        构造函数前所有的存储属性值都必须赋值
        super.init()
        
        spliteEmoticons()
    }
    
    private func spliteEmoticons()
    {
//        计算总页数
        let pageCount = (emoticons.count + emoticonsOfPage - 1)/emoticonsOfPage
        
        if pageCount == 0
        {
            let pageEmoticon = [HMEmoticonModel]()
            pageEmoticons.append(pageEmoticon)
        }
        
        for i in 0..<pageCount
        {
            let location = i * emoticonsOfPage
            var length = emoticonsOfPage
            
            if location + length > emoticons.count
            {
                length = emoticons.count - location
            }
            
            let range = NSRange(location: location, length: length)
            
            let subEmotions = (emoticons as NSArray).subarrayWithRange(range) as! [HMEmoticonModel]
            
            pageEmoticons.append(subEmotions)
        }
    }

}








